In the configuration file (.CNF), the BUS section must be declared so that you have the hardware resources required for the implementation of the COUNTER2 device. There must be at least one bidirectional meter. The device can also use an interrupt line for the snap functions count on interrupt (such as uploading preset quota).
In the INTDEVICE section of the .CNF file must be added the following definition:
;--------------------------------- ; Internal device declaration ;--------------------------------- INTDEVICE .. <device_name> COUNTER2 TCamp QCTL IntL
![]() | It is necessary that each definition are present on the same line. In case you do not want to assign a resource such as IntL, you still must enter in the appropriate field the string X. |
|---|
where:
| <device name> | Name assigned to the device. |
| COUNTER2 | Keyword that identifies the device bi-directional meter. |
| TCamp | Sample time device (1÷255 ms). |
| QCTL | Address tab counter. |
| IntL | Hardware interrupt line number dedicated for transducer zero pulse during the capture phase of the count (to prevent the device uses this resource to put the X character). |
;--------------------------------- ; Internal device declaration ;--------------------------------- INTDEVICE Count COUNTER2 2 2.CNT02 3
To use the device you must define the transducer resolution.
cntratio = (space covered in units of measure / pulses turn encoder) x 100000
This allows conversion constant to transduce the pulses read in space covered by the axis. The relationship space/pulse can assume values between 0,00374 eand 4,00000 but, having to be introduced in an integer parameter, must be multiplied by 100000.
Once set correctly the resolution it will be possible to read the instantaneous position of the axis (in unit of measure) on the posit parameter.
You can lock and unlock the updating with CNTLOCK andCNTUNLOCK commands.
You can reverse and restore the counter direction with CNTREV and CNTDIR commands.
The INTENBL and INTDSBL commands enable and disable the interrupt line connected to the transducer's zero pulse. The value of the capture parameter defines on which this impulse will be frozen on instantaneous count; the count caught is placed in the delta parameter.
![]() | The modify of the resolution value (cntratio) or the writing of the posit variable, causes the reset of the remnants of the conversion. |
|---|
The device always shows the absolute position of the axis; the counter change can be executed alsowith the direct writing in the new value on the posit paramenter.
Wanting to steal 100 units of measure to the count you can:
Axis:posit = Axis:posit - 100
This introduces an error because it imposes the location “posit = -100”, when the axis could have an intermediate position between a unit of measurement and subsequent (esxample 100.3). This fraction (0.3) is lost and the repetition of these steps will the accumulation of a considerable error.
The DELCNT command sum at the count an amount equal to thedelta parameter without losing the fraction part of the position:
Axis:delta = -100
DELCNT Axis
The reading of the axis is of 2 units and is located at point A. You want to add to the count posit three units of measure.
With the instructions:
Axis:posit = Axis:posit + 2
the axis takes the new B position.
With the instructions:
Axis:delta = 2
DELCNT Axis
the axis takes the C position C.
Note that with the first instructions the axis took a delta less than 3 units and then introduced an error.
If you need to send DELCNT commands in succession, It is convenient to calculate the greatness to be summed and send once the command; otherwise Beware not to send subsequent commands without a read statement on device parameter.
Axis:delta = 3
DELCNT Axis
WAIT Axis:st_init
Axis:delta = 40
DELCNT Axis
The name of the parameter, state oo command comando is shown to the left side of the table.
R
Indicates whether its parameter or state is retentive (upon initialization of the device maintains the previously state defined), or the state assumes upon initialization of the device.
If the device does not need to initialize the field “R” indicates the value that the parameter or state presenting to power up of the card.
R = Retentive
0 = Upon initialization of the device the value is forced to zero.
1 = Upon initialization of the device the value is forced to one.
- = Upon initialization of the device is presented significant value.
D
Indicates the size of the parameter.
F = Flag
B = Byte
W = Word
L = Long
S = Single Float
Vengono descritte tutte le condizioni necessarie affinché il parametro sia considerato corretto o perché il comando venga accettato.
In alcuni casi vengono specificati dei valori limite per laccettazione del parametro: se vengono
introdotti dei valori esterni ai limiti impostati, il dato viene comunque accettato; pertanto
devono essere previsti opportuni controlli dellapplicativo tali da garantire il corretto funzionamento.
Per lesecuzione di un comando, tutte le relative condizioni devono necessariamente essere
soddisfatte; in caso contrario il comando non viene inviato.
A
Indica la modalità di accesso.
R = Read (lettura).
W = Write (scrittura).
RW = Read / Write.
I comandi sono stati ordinati con priorità decrescente. Ad esempio, in caso di contemporaneità dei comandi CNTLOCK ed CNTUNLOCK, viene acquisito per primo il comando CNTLOCK.
| Nome | Condizioni | Descrizione |
|---|---|---|
| CNTLOCK | st_init = 1 | Counter lock Blocca l'acquisizione del conteggio asse anche se il trasduttore continua ad inviare i segnali. In questa fase l'eventuale spostamento dell'asse non viene rilevato. Attiva lo stato st_cntlock. |
| CNTUNLOCK | st_init = 1 | Counter unlock Sblocca il conteggio dell'asse. Viene riabilitato l'aggiornamento del conteggio. Disattiva lo stato st_cntlock. |
| CNTREV | st_init = 1 | Counter reverse Consente di invertire le fasi del trasduttore all'interno della scheda. Viene quindi invertito il senso del conteggio (incremento/decremento). Attiva lo stato st_cntrev. |
| CNTDIR | st_init = 1 | Counter direct Il conteggio dell'asse non viene invertito Disattiva lo stato st_cntrev. |
| INTENBL | st_init = 1 capture>0 1£ IntL £ 8 | Interrupt enable Abilita cattura del conteggio che verrà memorizzato in delta. Attiva lo stato st_intenbl. |
| INTDSBL | st_init = 1 | Interrupt disable Disabilita la cattura del conteggio. Disattiva lo stato st_intenbl. |
| RSCAPTURE | st_init = 1 | Reset capture Disattiva lo stato di st_capture |
| DELCNT | st_init = 1 st_intenbl = 0 | Delta counter Il conteggio (posizione dell'asse) viene modificato sommandogli algebricamente il valore specificato nel parametro delta (posit = posit + delta). |
| Nome | D | R | A | Condizioni | Descrizione |
|---|---|---|---|---|---|
| cntratio | L | R | R-W | Nessuna | Counter ratio Definisce per quanto vanno moltiplicati gli impulsi del trasduttore in modo che l'acquisizione degli spostamenti venga espressa nell'unità di misura desiderata. Impostando 100000 la variazione del conteggio è di 1 bit per impulso trasduttore. Range valido: 374 ÷ 400000 |
| posit | L | R | R-W | Nessuna | Actual position È il valore della posizione istantanea dell'asse. Valore espresso in unità di misura (Um). Range valido: -999999 ÷ 999999 |
| delta | L | R | R-W | Nessuna | Delta counter È il valore che viene sommato al conteggio quando viene inviato un comando DELCNT. Valore espresso in unità di misura(Um). Range valido: -999999 ÷ 999999. |
| capture | B | R | R-W | Nessuna | Capture mode Definisce il modo di cattura del conteggio su interrupt hardware. 0 = Disabilitato. 1 = Singola cattura sul fronte di discesa. 2 = Singola cattura sul fronte di salita. N.B. La cattura del conteggio è abilitata se lo stato st_intenbl = 1. |
| Nome | D | R | A | Condizioni | Descrizione |
|---|---|---|---|---|---|
| st_cntlock | F | R | R | Nessuna | Counter locked Segnalazione di conteggio asse bloccato. 0 = Conteggio asse sbloccato. 1 = Conteggio asse bloccato. |
| st_cntrev | F | R | R | Nessuna | Counter reversed Segnalazione di conteggio asse invertito. 0 = Conteggio asse non invertito. 1 = Conteggio asse invertito. |
| st_intenbl | F | 0 | R | Nessuna | Interrupt enabled Segnala l'abilitazione alla cattura del conteggio da linea di interrupt hardware. Viene attivato dal comando INTENBL e disattivato dal comando INTDSBL. viene disattivato automaticamente a cattura avvenuta. 0 = Cattura del conteggio non è abilitata. 1 = Cattura del conteggio abilitata. |
| st_capture | F | 0 | R | Nessuna | Counter capture Viene attivato alla cattura del conteggio; viene resettato dal comando RSCAPTURE. 0 = Cattura del conteggio non eseguita. 1 = Eseguita cattura conteggio. |
Se viene modificato il parametro cntratio successivamente allinvio del comando DELCNT, vengono azzerati i resti della conversione del delta spazio in impulsi.
;*************************************************************************************
; Nome Modulo: Ex_Count.CNF Progetto: Ex_COUNT
; Autore: QEM srl Data : 01/05/99
; Sistema: QMove1 / QCL3 Libreria: 1LIB3B04
; Funzionalità: Esempio gestione CPUNTER Release: 0
;------------------------------------- Note ------------------------------------------
; [1] - Applicativo di esempio per utilizzo device COUNTER 2
;*************************************************************************************
;-------------------------------------------------------------------------------------
; Definizione Costanti
;-------------------------------------------------------------------------------------
CONST
;-------------------------------------------------------------------------------------
; Definizione Variabili SYSTEM
;-------------------------------------------------------------------------------------
SYSTEM
slPrsPos L ;Quota di preset
slSet1 L ;Setpoint 1
slSet2 L ;Setpoint 2
;-------------------------------------------------------------------------------------
; Definizione Variabili GLOBAL
;-------------------------------------------------------------------------------------
GLOBAL
;-------------------------------------------------------------------------------------
; Definizione Variabili TIMER
;-------------------------------------------------------------------------------------
TIMER
;-------------------------------------------------------------------------------------
; Definizione DATAGROUP
;-------------------------------------------------------------------------------------
;DATAGROUP
;-------------------------------------------------------------------------------------
; Configurazione Bus
;-------------------------------------------------------------------------------------
BUS
1 1CPUB 02
2 1MIXA 00
3 .
4 .
;-------------------------------------------------------------------------------------
; Definizione Variabili INPUT
;-------------------------------------------------------------------------------------
INPUT
ifAbilZ F 2.INP01 ;Abilitazione cattura impulso di zero
ifAxeFermo F 2.INP02 ;Segnalazione asse fermo
;-------------------------------------------------------------------------------------
; Definizione Variabili OUTPUT
;-------------------------------------------------------------------------------------
OUTPUT
ofGTSet1 F 2.OUT01 ;Segnalazione superamento setpoint 1 ->
ofLTSet2 F 2.OUT02 ;Segnalazione superamento setpoint 2 <-
;-------------------------------------------------------------------------------------
; Dichiarazione device interni
;-------------------------------------------------------------------------------------
INTDEVICE
;Nome Tipo TCamp Contatore Inter
Asse COUNTER2 2 2.CNT01 1
END
;*************************************************************************************
; Nome File: TASK_00.MOD
; Progetto : EX_COUNT
; Descrizione:Gestione Posizionamento
;*************************************************************************************
;-------------------------------------------------------------------------------------
; Operazioni di Inizializzazione Asse
;-------------------------------------------------------------------------------------
Asse:cntratio = 100000 ;Risoluz.encoder = Spazio in 1 giro
;encoder(Um) / impulsi giro encoder
Asse:capture = 1
IF slSet1 EQ 0
slSet1 = 500
ENDIF
IF slSet2 EQ 0
slSet2 = 100
ENDIF
;-------------------------------------------------------------------------------------
; Ricerca di preset abilitata ad ogni passaggio sul finecorsa
; ---------------------------- variabili utilizzate ---------------------------------
; slPrsPos : Quota di preset impostata
;--------------------------------------------------------------------------------------
MAIN:
IF ifAbilZ ;Attende l'ingresso di abilitazione
;impulso di zero trasduttore
INTENBL Asse ;Abilita la cattura dell'impulso di zero
;trasduttore
ELSE
INTDSBL Asse ;Disabilita la cattura dell'impulso di
;zero trasduttore
ENDIF
IF Asse:st_capture ;Se è stato catturato il conteggio
IF ifAxeFermo ;Se l'asse è fermo
Asse:delta = -(Asse:delta-slPrsPos) ;Calcolo quota da sommare al conteggio
DELCNT Asse ;Imposto il nuovo valore del conteggio
RSCAPTURE Asse ;Resetto st_capture dell'Asse
ENDIF
ENDIF
;-------------------------------------------------------------------------------------
; Comparazioni sul conteggio
; ----------------------------- variabili utilizzate --------------------------------
; slSet1: Quota di comparazione per uscita ofGTSet1
; slSet1: Quota di comparazione per uscita ofLTSet2
;-------------------------------------------------------------------------------------
IF Asse:posit GT slSet1 ;Se il conteggio è > del setpoint 1
SETOUT ofGTSet1 ;Attiva l'uscita ofGTSet1
ELSE
RESOUT ofGTSet1 ;Disattiva l'uscita ofGTSet1
ENDIF
IF Asse:posit LT slSet2 ;Se il conteggio è < del setpoint 2
SETOUT ofLTSet2 ;Attiva l'uscita ofLTSet2
ELSE
RESOUT ofLTSet2 ;Disattiva l'uscita ofLTSet2
ENDIF
;-------------------------------------------------------------------------------------
; Operazioni finali
;-------------------------------------------------------------------------------------
WAIT 1
JUMP MAIN
END